// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "resource.h"
#include <windows.h>
#include <richedit.h>
#include <stdio.h>
#include <dbghelp.h>
#include <shlwapi.h>
#include <commctrl.h>

#include "HookAPI.h"
#include "StackWalker.h"
#include "SimpleWindow.h"
#include "modulestree.h"
#include "callstack.h"
#include "heapproxy.h"
#include "ProfilingThread.h"
#include "psapi.h"

#pragma comment (lib,"Dbghelp.lib")
#pragma comment(lib,"shlwapi.lib")
#pragma comment(lib,"comctl32.lib");


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	__hModDLL = hModule;

	DWORD dwProcessId = ::GetCurrentProcessId();
	HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
                            PROCESS_VM_READ,
                            FALSE, dwProcessId );

	MODULEINFO mi;
	::GetModuleInformation( hProcess,hModule,&mi,sizeof(mi) );
	__dwModSize = mi.SizeOfImage;

	CloseHandle( hProcess );

	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		{						
			start_profile_thread( hModule );
		}
		break;
	case DLL_THREAD_ATTACH:
		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

